package solutions.leetcode.normal

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/finding-the-users-active-minutes/">1817. 查找用户活跃分钟数</a>
 */
private class Solution1817 {
    fun findingUsersActiveMinutes(logs: Array<IntArray>, k: Int): IntArray {
        val map = HashMap<Int, HashSet<Int>>()
        for (item in logs) {
            var set = map[item[0]]
            if (set == null) {
                set = HashSet()
                map[item[0]] = set
            }
            if (item[1] <= k) set.add(item[1])
        }
        val rst = IntArray(k)
        map.map { it.value.size }.filter { it > 0 }.forEach {
            rst[it - 1]++
        }
        return rst
    }
}

fun main() {
    println(
        Solution1817().findingUsersActiveMinutes(
            arrayOf(
                arrayOf(0, 5).toIntArray(),
                arrayOf(1, 2).toIntArray(),
                arrayOf(0, 2).toIntArray(),
                arrayOf(0, 2).toIntArray(),
                arrayOf(1, 3).toIntArray(),
            ),
            5
        ).toList()
    )
}